<?php
/*
  $Id: specials.php,v 1.31 2003/06/09 22:21:03 hpdl Exp $

 E-Commerce Solutions

  Copyright (c) 2005 www.flash-template-design.com

  Released under the GNU General Public License
*/

//  if ($random_product = tep_random_select("select p.products_id, pd.products_name, p.products_price, p.products_tax_class_id, p.products_image, s.specials_new_products_price from " . TABLE_PRODUCTS . " p, " . TABLE_PRODUCTS_DESCRIPTION . " pd, " . TABLE_SPECIALS . " s where p.products_status = '1' and p.products_id = s.products_id and pd.products_id = s.products_id and pd.language_id = '" . (int)$languages_id . "' and s.status = '1' order by s.specials_date_added desc limit " . MAX_RANDOM_SELECT_SPECIALS)) {
?>
<!-- specials //-->
			

<?php

   

   if ( (!isset($new_products_category_id)) || ($new_products_category_id == '0') ) {
    $new_products_query = tep_db_query("select p.products_id, pd.products_name, p.products_price, p.products_tax_class_id, p.products_image, s.specials_new_products_price from " . TABLE_PRODUCTS . " p, " . TABLE_PRODUCTS_DESCRIPTION . " pd, " . TABLE_SPECIALS . " s where p.products_status = '1' and p.products_id = s.products_id and pd.products_id = s.products_id and pd.language_id = '" . (int)$languages_id . "' and s.status = '1' order by s.specials_date_added desc limit " . MAX_RANDOM_SELECT_SPECIALS);
  }

 $info_box_contents = array();
    $info_box_contents[] = array('text' => 'Featured Products');
  
echo '<table width="410" height="339" cellspacing="0" cellpadding="0" style="margin-top:1px; border:1px solid #DED9C5;">
<tr>
	<td valign="top" height="23"  align="left">
		<table width="350" height="23" cellspacing="0" cellpadding="0">
			<tr>
			    <td align="left" valign="bottom" width="339" height="20" style="padding-left:7px; padding-bottom:1px; font:14px Tahoma; color:#FFFFFF; background:#D8CFA8;">'.HEADING_TITLE.'</td></tr>
			<tr>
				<td align="right" valign="top" width="339" height="3" style="background:#D8CFA8;">
					<table align="center" width="342" height="3" cellspacing="0" cellpadding="0">
						<tr>
							<td align="center" valign="bottom" height="3" style="background:#D8CFA8 repeat-x url(images/point-w.gif) top;"><img src="images/pixel_trans.gif" alt="" width="1" height="1" border="0"></td></tr>
					</table>
				</td></tr>
		</table>
	</td>
</tr>
<tr>
    <td border="0" height="251" align="left" valign="top"  bgcolor="#ffffff">';
	
  $row = 0;
  $col = 0;
  $info_box_contents = array();
  while ($new_products = tep_db_fetch_array($new_products_query)) {
    $new_products['products_name'] = tep_get_products_name($new_products['products_id']);
	
	$sql = 'SELECT `products_description` FROM `products_description` WHERE products_id ='.$new_products['products_id'].' && language_id='.(int)$languages_id;
	$description_query = tep_db_query($sql);
	$description = mysql_fetch_array($description_query, MYSQL_ASSOC);        
	$description['products_description'] = substr($description['products_description'], 0, 350);
	//$desc_len = strlen($description['products_description']);
	//$description['products_description'][$desc_len-1] = '.';
	//$description['products_description'][$desc_len-2] = '.';
	//$description['products_description'][$desc_len-3] = '.';

    $info_box_contents[$row][$col] = array('align' => 'center',
                                           'params' => 'width="33%" height="230" style="padding-top:2px;"',
                                           'text' => '

<div class="new_prod" valign="top">
<div class="new_prod3" valign="top">
<div class="new_prod1"><b>'.$new_products['products_name'].'</b></div>
<div class="new_prod2" align="center">'.$description['products_description'].'</div>

<div class="image" style="background:no-repeat url('.DIR_WS_IMAGES . $new_products['products_image'].');"><a href="'. tep_href_link(FILENAME_PRODUCT_INFO, 'products_id=' . $new_products['products_id']) .'"><img src="images/new.gif" alt="'.$new_products['products_name'].'" width="88" height="118" border="0"></a></div>
<div class="price"><span style="font:bold 11px Tahoma; color:#303030;">Price:&nbsp;</span> '. $currencies->display_price($new_products['products_price'], tep_get_tax_rate($new_products['products_tax_class_id'])).'</div>
</div>
<div style=" width:146px; height:2px;"><img src="images/h-line-spec.gif" alt="" width="146" height="2" border="0"></div>
<div class="buy">'.tep_draw_form('cart_quantity', tep_href_link(FILENAME_PRODUCT_INFO, tep_get_all_get_params(array('action')) . 'action=add_product')).'
<a href="'.tep_href_link(FILENAME_PRODUCT_INFO, 'products_id=' . $new_products['products_id']).'"><img src="images/bdetails.gif" alt="" width="58" height="17" border="0" /></a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
'. tep_draw_hidden_field('products_id', $new_products['products_id']) . tep_image_submit('add_to_cart.gif', IMAGE_BUTTON_IN_CART,' width="86" height="16"') .'</form>
</div>
</div>
');
    $col ++;
	if ($col >=5) {break;}
	$info_box_contents[$row][$col] = array('align' => 'center',
                                           'params' => 'width="1%" height="230" style="padding-top:2px;"',
                                           'text' => '<img src="images/v-line-spec.gif" alt="" width="3" height="250" border="0">');
	$col ++;
	
  }
  
  $dop_col=$col;

  if($dop_col<3)
  {
    if ( (!isset($new_products_category_id)) || ($new_products_category_id == '0') ) {
    $new_products_query = tep_db_query("select p.products_id, p.products_image, p.products_tax_class_id, if(s.status, s.specials_new_products_price, p.products_price) as products_price from " . TABLE_PRODUCTS . " p left join " . TABLE_SPECIALS . " s on p.products_id = s.products_id where products_status = '1' order by p.products_date_added desc limit " . MAX_DISPLAY_NEW_PRODUCTS);
  } else {
    $new_products_query = tep_db_query("select distinct p.products_id, p.products_image, p.products_tax_class_id, if(s.status, s.specials_new_products_price, p.products_price) as products_price from " . TABLE_PRODUCTS . " p left join " . TABLE_SPECIALS . " s on p.products_id = s.products_id, " . TABLE_PRODUCTS_TO_CATEGORIES . " p2c, " . TABLE_CATEGORIES . " c where p.products_id = p2c.products_id and p2c.categories_id = c.categories_id and c.parent_id = '" . (int)$new_products_category_id . "' and p.products_status = '1' order by p.products_date_added desc limit " . MAX_DISPLAY_NEW_PRODUCTS);
  }

  $row = 0;
  $col = $dop_col;
 // $info_box_contents = array();
  while ($new_products = tep_db_fetch_array($new_products_query)) {
    $new_products['products_name'] = tep_get_products_name($new_products['products_id']);
	$bb="&#9635; ";
	$sql = 'SELECT `products_description` FROM `products_description` WHERE products_id ='.$new_products['products_id'].' && language_id='.(int)$languages_id;
	$description_query = tep_db_query($sql);
	$description = mysql_fetch_array($description_query, MYSQL_ASSOC);
	//$description = $description.$bb;
	$description['products_description'] = substr($description['products_description'], 0, 350);
	//$desc_len = strlen($description['products_description']);
	//$description['products_description'][$desc_len-1] = '.';
	//$description['products_description'][$desc_len-2] = '.';
	//$description['products_description'][$desc_len-3] = '.';

	//�������� index

    $info_box_contents[$row][$col] = array('align' => 'center',
                                           'params' => 'width="33%" height="100%" style="padding-top:2px;"',
                                           'text' => '

<div class="new_prod" valign="top">
<div class="new_prod3" valign="top">
<div class="new_prod1"><b>'.$new_products['products_name'].'</b></div>
<div class="new_prod2" align="center">'.$description['products_description'].'</div>

<div class="image" style="background:no-repeat url('.DIR_WS_IMAGES . $new_products['products_image'].');"><a href="'. tep_href_link(FILENAME_PRODUCT_INFO, 'products_id=' . $new_products['products_id']) .'"><img src="images/new.gif" alt="'.$new_products['products_name'].'" width="88" height="118" border="0"></a></div>
<div class="price"><span style="font:bold 11px Tahoma; color:#303030;">Price:&nbsp;</span> '. $currencies->display_price($new_products['products_price'], tep_get_tax_rate($new_products['products_tax_class_id'])).'</div>
</div>
<div style=" width:146px; height:2px;"><img src="images/h-line-spec.gif" alt="" width="146" height="2" border="0"></div>
<div class="buy">'.tep_draw_form('cart_quantity', tep_href_link(FILENAME_PRODUCT_INFO, tep_get_all_get_params(array('action')) . 'action=add_product')).'
<a href="'.tep_href_link(FILENAME_PRODUCT_INFO, 'products_id=' . $new_products['products_id']).'"><img src="images/bdetails.gif" alt="" width="58" height="17" border="0" /></a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
'. tep_draw_hidden_field('products_id', $new_products['products_id']) . tep_image_submit('add_to_cart.gif', IMAGE_BUTTON_IN_CART,' width="86" height="16"') .'</form>
</div>
</div>
');
    $col ++;
	if ($col >=5) {break;}
	$info_box_contents[$row][$col] = array('align' => 'center',
                                           'params' => 'width="1%" height="230" style="padding-top:2px;"',
                                           'text' => '<img src="images/v-line-spec.gif" alt="" width="3" height="250" border="0">');
	$col ++;
  }
 }
  //new contentBox2($info_box_contents, 0);
?>
<?php echo '</td></tr></table>';?>            
            
<!-- specials_eof //-->

